﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


using Microsoft.VisualStudio.TestTools.UnitTesting;
using Sherwood.Mvc.Localization;
using Sherwood.Localization;
using Sherwood.Localization.Resx;

namespace Sherwood.Mvc.Tests
{
    [TestClass]
    public class TranslationOutputFilterTests
    {

        /// <summary>
        /// Test the translation output filter.
        /// We expect the filter to lookup anything between [$  $] in the translation dictionary.
        /// We expect that a lookup like "Ha det bra!" will implicitly be converted to a key consisting of only alphanumeric characters without spaces.
        /// Ie. "Ha det bra!" should lookup "Hadetbra" in the dictionary and "1du og!" should lookup "duog" (no numbers allowed at the start of a key).
        /// We also expect that a translation phrase can be split over two subsequent strings (in which case it will be included in the second output string).
        /// </summary>
        [TestMethod]
        public void TranslationOutputFilterTest()
        {
            //Assemble
            ITranslationProvider provider = new ResxTranslationProvider(typeof(Resources.SherwoodMvcTests), "en");
            string input1 = "This is a little [!no real key!] test [!en!] and some more [!to!]. [!Ha det bra!!]. [!1du og!!] [!en ting";
            string input2 = "til !] and that's it!";
            string expectedOutput1 = "This is a little no real key test one and some more two. Good bye. You too! ";
            string expectedOutput2 = "One more thing and that's it!"; 
            TranslationOutputFilter filter = new TranslationOutputFilter(null,provider);

            //Act
            string output1 = filter.Translate(input1);
            string output2 = filter.Translate(input2); 

            //Assert
            Assert.AreEqual<string>(expectedOutput1, output1);
            Assert.AreEqual<string>(expectedOutput2, output2);
            

        }
    }
}
